load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@aspect_rules_ts//ts:defs.bzl", rules_js_tsconfig = "ts_config")
load("//tools:defaults.bzl", "jasmine_test", "npm_package", "ts_project")

package(default_visibility = [":__subpackages__"])

copy_to_bin(
    name = "schematics_assets",
    srcs = glob(
        [
            "**/files/**/*",
            "**/*.json",
        ],
        exclude = [
            "tsconfig.json",
            "tsconfig-test.json",
            "package.json",
        ],
    ),
)

copy_to_bin(
    name = "package_json",
    srcs = ["package.json"],
)

rules_js_tsconfig(
    name = "tsconfig",
    src = "tsconfig.json",
)

rules_js_tsconfig(
    name = "tsconfig_test",
    src = "tsconfig-test.json",
    deps = [
        ":tsconfig",
    ],
)

ts_project(
    name = "schematics",
    srcs = glob(
        ["**/*.ts"],
        exclude = [
            "**/files/**/*",
            "**/*.spec.ts",
            "testing/**/*.ts",
        ],
    ),
    tsconfig = ":tsconfig",
    deps = [
        "//:node_modules/@angular-devkit/core",
        "//:node_modules/@angular-devkit/schematics",
        "//:node_modules/@schematics/angular",
        "//:node_modules/@types/node",
        "//:node_modules/glob",
        "//:node_modules/parse5",
        "//:node_modules/typescript",
        "//src/cdk/schematics/update-tool",
    ],
)

# This package is intended to be combined into the main @angular/cdk package as a dep.
npm_package(
    name = "npm_package",
    srcs = [
        "package.json",
        ":schematics",
        ":schematics_assets",
    ],
    package = "@angular/cdk/schematics",
    visibility = [
        "//src/cdk:__pkg__",
        "//src/material/schematics:__pkg__",
    ],
)

ts_project(
    name = "unit_test_sources",
    testonly = True,
    srcs = glob(
        ["**/*.spec.ts"],
        exclude = [
            "**/*.e2e.spec.ts",
            "**/files/**/*.spec.ts",
        ],
    ),
    tsconfig = "tsconfig_test",
    deps = [
        ":schematics",
        "//:node_modules/@angular-devkit/schematics",
        "//:node_modules/@bazel/runfiles",
        "//:node_modules/@schematics/angular",
        "//:node_modules/@types/jasmine",
        "//:node_modules/@types/node",
        "//:node_modules/parse5",
        "//:node_modules/typescript",
        "//src/cdk/schematics/testing",
        "//src/cdk/schematics/update-tool",
        "//src/cdk/testing/private",
    ],
)

jasmine_test(
    name = "unit_tests",
    data = [
        ":schematics_assets",
        ":unit_test_sources",
    ],
)
